﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace calculator2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            try
            {
                double num1 = Convert.ToDouble(numInput1.Text);
                double num2 = Convert.ToDouble(numInput2.Text);
                double result1 = double.NaN;
                switch (op.Text)
                {
                    case "+":
                        result1 = num1 + num2;
                        break;
                    case "-":
                        result1 = num1 - num2;
                        break;
                    case "*":
                        result1 = num1 * num2;
                        break;
                    case "/":
                        if (num2 != 0)
                        {
                            result1 = num1 / num2;
                        }
                        break;
                    default:                        
                        break;
                }
                result.Text = "计算结果：" + result1;
            }
            catch
            {
                result.Text = "数据错误";
            }
        }
    }
}
